package com.example.administrator.myapplication;

import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.nfc.Tag;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {
    private static final String TAG="MainActivity";
    TextView mTvResult;
    Button mBtnProgress;
    ProgressDialog progressDialog;
    Button mBtnMyDialog;
    private void showProgressDialog(){
        ProgressDialog progressDialog = new ProgressDialog(this);
        progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
        progressDialog.show();
    }
    private  void closeProgressDialog(){
    progressDialog.dismiss();
    }

    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mBtnMyDialog=findViewById(R.id.btn_mydialog);
        mBtnMyDialog.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyDialog myDialog = new MyDialog(MainActivity.this);
                myDialog.setTitle("标题");
                myDialog.show();
            }
        });
        mBtnProgress=findViewById(R.id.btn_progress);
        mBtnProgress.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                showProgressDialog();
                Thread thread = new Thread(new Runnable() {
                    @Override
                    public void run() {
                        try {
                            Thread.sleep(5000);
                            closeProgressDialog();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                });
                //启动线程
                thread.start();
            }
        });
        mTvResult=findViewById(R.id.tv_result);
        mTvResult.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                AlertDialog dialog = new AlertDialog.Builder(MainActivity.this)
                        .setTitle("请选择口味：")
                        .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                            @Override
                            public void onClick(DialogInterface dialog, int which) {

                            }
                        })
                        .setNegativeButton("取消",null)
                        .setIcon(R.mipmap.ic_launcher)
                        .setMultiChoiceItems(new String[]{"辣","粉","牛肉"},null,null)

                        .create();
                dialog.show();
            }
        });

    }

    public void setmTvResult(String mTvResult) {
        mTvResult = mTvResult;
    }
}
